﻿            using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Liger.Web.Common;
using Liger.Web.Common.Extensions;

namespace Liger.Web.UI
{
    public class FormBuilder : UIComponentBuilderBase , IHideObjectMembers
    {
        private Form Form
        {
            get
            {
                return this.Component as Form;
            }
        }
         

        public FormBuilder()
            : base(new Form())
        {

        }

        public FormBuilder(Form Form)
            : base(Form)
        { 

        }

        /// <summary>
        /// 设置属性
        /// </summary>
        /// <param name="property"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public FormBuilder Set(string property, object value)
        {
            if (this.Form.Properties.ContainsKey(property))
            {
                this.Form.Properties[property] = value;
            }
            else
            {
                this.Form.Properties.Add(property, value);
            }
            return this;
        }

        /// <summary>
        /// 返回ligerForm的Manager
        /// </summary>
        /// <param name="manager">manager的对象名</param>
        /// <returns></returns>
        public FormBuilder Manager(string manager)
        {
            this.Form.Manager = manager;
            return this;
        }

        /// <summary>
        /// 列配置
        /// </summary>
        /// <param name="action"></param>
        /// <returns></returns>
        public FormBuilder Fields(Action<FormFieldsBuilder> action)
        {
            if (action != null)
            {
                action(new FormFieldsBuilder(this.Form.Fields));
            }
            return this;
        }

        /// <summary>
        /// InputWidth
        /// </summary>
        public FormBuilder InputWidth(int value)
        {
            this.Form.InputWidth = value;
            return this;
        }

        /// <summary>
        /// LabelWidth
        /// </summary>
        public FormBuilder LabelWidth(int value)
        {
            this.Form.LabelWidth = value;
            return this;
        }


        /// <summary>
        /// Space
        /// </summary>
        public FormBuilder Space(int value)
        {
            this.Form.Space = value;
            return this;
        }

        /// <summary>
        /// RightToken
        /// </summary>
        public FormBuilder RightToken(string value)
        {
            this.Form.RightToken = value;
            return this;
        }

        /// <summary>
        /// LabelAlign
        /// </summary>
        public FormBuilder LabelAlign(string value)
        {
            this.Form.LabelAlign = value;
            return this;
        }

        /// <summary>
        /// Align
        /// </summary>
        public FormBuilder Align(string value)
        {
            this.Form.Align = value;
            return this;
        }

        /// <summary>
        /// AppendID
        /// </summary>
        public FormBuilder AppendID(bool value)
        {
            this.Form.AppendID = value;
            return this;
        }

        /// <summary>
        /// PrefixID
        /// </summary>
        public FormBuilder PrefixID(string value)
        {
            this.Form.PrefixID = value;
            return this;
        }

        /// <summary>
        /// ToJSON
        /// </summary>
        public FormBuilder ToJSON(string tojson)
        {
            this.Form.ToJSON = () => tojson;
            return this;
        }
    }
}
